package com.qianfeng.openapi.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qianfeng.openapi.mapper.CustomerMapper;
import com.qianfeng.openapi.pojo.Customer;
import com.qianfeng.openapi.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional
public class CustomerServiceImpl implements CustomerService {
    @Autowired
    private CustomerMapper customerMapper;


    @Override
    public Customer selectCustomerById(int id) {

        return customerMapper.queryCustomerById(id);
    }



    @Override
    public void updateCustomer(Customer customer){

        customerMapper.updateCustomer(customer);
    }

    @Override
    public void deleteCustomer(int[] ids) {

        customerMapper.deleteCustomer(ids);
    }

    @Override
    public void insertCustomer(Customer customer) {

        customerMapper.insertCustomer(customer);
    }



    @Override
    public PageInfo<Customer> selectCustomerWhere(int page, int limit, Customer customer) {
        PageHelper.startPage(page,limit);
        List<Customer> customers = customerMapper.queryCustomerByNameAndState(customer);
        PageInfo<Customer> pageInfo=new PageInfo<>(customers);
        return pageInfo;
    }



    @Override
    public List<Customer> getAllCustomer() {
        return customerMapper.getCustomers();
    }

    @Override
    public void addMoney(Long money, Integer id) {
        Customer customer=customerMapper.queryCustomerById(id);
        if (customer!=null){
            customer.setMoney(customer.getMoney()+money);
            customerMapper.updateCustomer(customer);
        }
    }
}
